package com.youpai.platform.common.entity.resp;

import com.youpai.platform.common.constant.NumberConstant;
import com.youpai.platform.common.entity.code.BaseProcessCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author welles
 * @version 1.0
 * @description 返回报文
 * @date 2021/7/22
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseResponse<T> {

    private String code;

    private String msg;

    private Boolean isSuccess;

    private T data;

    public static <T> BaseResponse<T> success() {
        return new BaseResponse<T>(BaseProcessCode.SUCCESS_CODE, BaseProcessCode.SUCCESS_DESC, NumberConstant.TRUE, null);
    }

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<T>(BaseProcessCode.SUCCESS_CODE, BaseProcessCode.SUCCESS_DESC, NumberConstant.TRUE, data);
    }

    public static <T> BaseResponse<T> fail(String code, String msg) {
        return new BaseResponse<>(code, msg, NumberConstant.FALSE, null);
    }

    public static <T> BaseResponse<T> fail(BaseProcessCode baseProcessCode) {
        return new BaseResponse<T>(baseProcessCode.getCode(), baseProcessCode.getDesc(), NumberConstant.FALSE, null);
    }
}
